<!-- 设备管理-设备列表页面 -->
<template>
  <div class="app-container" style="height: 100%; margin: 0">
    <px-form v-show="showSearch" ref="queryRef" class="custom-form-ui" :model="queryParams" :inline="true" label-width="90px">
      <!-- <px-form-item label="系统">
        <px-select
          v-model="queryParams.systemCode"
          placeholder="请选择系统"
          clearable
          style="width: 240px"
          filterable
          @change="queysetSystemChemicals"
        >
          <px-option v-for="dict in liquidList" :key="dict.itemValue" :label="dict.itemName" :value="dict.itemValue" />
        </px-select>
      </px-form-item> -->
      <px-form-item label="排放计划">
        <!-- <px-select v-model="queryParams.emissionPlan" placeholder="请选择" clearable style="width: 240px" filterable>
          <px-option v-for="dict in querychemicalList" :key="dict" :label="dict" :value="dict" />
        </px-select> -->
        <px-input v-model="queryParams.emissionPlan" placeholder="请输入" style="width: 240px" clearable />
      </px-form-item>
      <px-form-item label="日期" style="width: 516px !important">
        <px-date-picker
          v-model="dateRange"
          type="datetimerange"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          format="YYYY-MM-DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
          :default-time="defaultTime"
        />
      </px-form-item>
      <px-button style="margin-top: -17px" type="primary" icon="" @click="handleQuery('search')">搜索</px-button>
      <px-button style="margin-top: -17px" icon="" @click="resetQuery">重置</px-button>
    </px-form>

    <px-row :gutter="10" class="mb8">
      <px-col :span="1.5">
        <px-button v-has="'EMISSION_PLAN_ADD'" type="primary" icon="" @click="handleAdd">新增</px-button>
      </px-col>
      <!-- <px-col :span="1.5">
        <px-button v-has="'CommonEquipListAdd'" type="primary" plain icon="" :disabled="multiple" @click="handleChuku">出库</px-button>
      </px-col> -->
      <!-- <px-col :span="1.5">
        <px-button type="primary" plain icon="" @click="handleExport">导出报表</px-button>
      </px-col> -->

      <!-- <px-col :span="1.5">
        :disabled="multiple"
        <px-button v-has="'CommonEquipListDelete'" type="danger" plain icon="" :disabled="multiple" @click="handleDelete">删除</px-button>
      </px-col> -->
    </px-row>

    <px-table v-if="!equipopen && !equipopenDetail" v-loading="loading" :data="typeList" height="calc(100vh - 319px)" show-overflow-tooltip border>
      <!-- <px-table-column type="selection" width="40" /> -->
      <px-table-column label="排放计划" prop="readDate">
        <template #default="scope">
          <span>{{ scope.row.emissionPlan }}</span>
        </template>
      </px-table-column>
      <px-table-column label="排放时间" prop="planTime">
        <template #default="scope">
          <span>{{ scope.row.emissionTime }}</span>
        </template>
      </px-table-column>
      <px-table-column fixed="right" label="操作" align="center" width="140">
        <template #default="scope">
          <px-button v-has="'EMISSION_PLAN_DETAIL'" link type="primary" @click="handleDetail(scope.row.emissionPlan)">
            <px-tooltip class="box-item" content="详情" placement="top">
              <px-icon>
                <Tickets />
              </px-icon> </px-tooltip
          ></px-button>
          <px-button
            v-if="scope.row.status != 'INVALID'"
            v-has="'EMISSION_PLAN_EDITOR'"
            link
            type="primary"
            @click="handleEditor(scope.row.emissionPlan)"
          >
            <px-tooltip class="box-item" content="编辑" placement="top">
              <px-icon>
                <EditPen />
              </px-icon> </px-tooltip
          ></px-button>
          <px-button
            v-if="scope.row.status != 'INVALID'"
            v-has="'EMISSION_PLAN_DELETE'"
            link
            type="danger"
            @click="handleDelete(scope.row.emissionPlan)"
            ><px-tooltip class="box-item" content="删除" placement="top">
              <px-icon>
                <Delete />
              </px-icon> </px-tooltip
          ></px-button>
        </template>
      </px-table-column>
      <template #empty>
        <px-empty :image-size="150" />
      </template>
    </px-table>

    <pagination
      v-if="!equipopen && !equipopenDetail"
      v-show="total > 0"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      style="margin-bottom: -10px"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->

    <px-scrollbar v-if="equipopen" class="editorEquip">
      <px-button style="margin-left: 24px" type="primary" :icon="ArrowLeft" @click="cancel">返回</px-button>
      <px-descriptions style="padding: 20px" class="margin-top" title="基本信息" :column="3" border>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">排放计划:</div>
          </template>
          {{ equipdata.emissionPlan }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">排放时间:</div>
          </template>
          {{ equipdata.emissionTime }}
        </px-descriptions-item>
      </px-descriptions>
      <div style="width: 100%; padding: 0 0 0 20px; clear: both">
        <div class="px-descriptions__title" style="margin-bottom: 16px">危险废弃物</div>
        <px-scrollbar style="height: 93px">
          <div class="tableTop">
            <div class="topList">废弃物名称</div>
            <div v-for="(item, index) in equipdata.wasteMap.HAZARD" :key="index" class="topList">
              {{ item.wasteName }}
            </div>
          </div>
          <div class="tableMain">
            <div class="topList">排放数量</div>
            <div v-for="(item, index) in equipdata.wasteMap.HAZARD" :key="index" class="topList">
              {{ item.emissionQuantity }}
            </div>
          </div>
        </px-scrollbar>
        <div class="px-descriptions__title" style="margin-bottom: 16px">一般废弃物</div>
        <px-scrollbar style="height: 93px">
          <div class="tableTop">
            <div class="topList">废弃物名称</div>
            <div v-for="(item, index) in equipdata.wasteMap.GENERAL" :key="index" class="topList">
              {{ item.wasteName }}
            </div>
          </div>
          <div class="tableMain">
            <div class="topList">排放数量</div>
            <div v-for="(item, index) in equipdata.wasteMap.GENERAL" :key="index" class="topList">
              {{ item.emissionQuantity }}
            </div>
          </div>
        </px-scrollbar>
      </div>
    </px-scrollbar>
    <px-scrollbar v-if="equipopenDetail" class="addEquip">
      <px-button style="margin-left: 24px" type="primary" :icon="ArrowLeft" @click="equipopenDetailcancel">返回</px-button>
      <px-form
        ref="detailruleFormRef"
        :disabled="fromdisable"
        :rules="rules"
        :model="equipdata"
        :inline="true"
        class="demo-form-inline"
        label-width="160px"
      >
        <div
          class="box-card1"
          :style="{
            height: jibenxinxiFlg == true ? '' : '42px'
          }"
        >
          <div class="card-header" @click="setqingdanFlg()">
            <div class="card-title">废弃物排放计划</div>
            <div class="card-main">
              <px-icon v-if="!jibenxinxiFlg">
                <ArrowDown />
              </px-icon>
              <px-icon v-else>
                <ArrowUp />
              </px-icon>
            </div>
          </div>
          <div class="form-div">
            <px-row>
              <px-col :span="12">
                <px-form-item label="排放计划" prop="emissionPlan">
                  <px-input v-model="equipdata.emissionPlan" placeholder="请输入" clearable /> </px-form-item
              ></px-col>
              <px-col :span="12">
                <px-form-item label="排放时间" prop="emissionTime">
                  <px-date-picker
                    v-model="equipdata.emissionTime"
                    :disabled="buttonTitle == '编辑'"
                    style="width: calc(100% - 100px)"
                    placeholder="请选择日期"
                    type="datetime"
                    format="YYYY-MM-DD HH:mm:ss"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  /> </px-form-item
              ></px-col>
            </px-row>
          </div>
        </div>
        <div
          class="box-card2"
          :style="{
            height: moxingshezhiFlg == true ? '' : '42px'
          }"
        >
          <div class="card-header" @click="setmoxingshezhiFlg()">
            <div class="card-title">一般废弃物</div>
            <div class="card-main">
              <px-icon v-if="!moxingshezhiFlg">
                <ArrowDown />
              </px-icon>
              <px-icon v-else>
                <ArrowUp />
              </px-icon>
            </div>
          </div>
          <px-button style="margin: 16px 0 -11px 23px" type="primary" plain size="small" @click="handleAddtestItems2">新增</px-button>
          <px-scrollbar class="form-div">
            <px-table :data="equipdata.wasteMap.GENERAL" border style="width: 100%">
              <px-table-column label="废弃物名称">
                <template #default="scope">
                  <px-select v-model="scope.row.dictWasteCode" placeholder="请选择系统" clearable style="width: 240px" filterable>
                    <px-option v-for="dict in GENERALlist" :key="dict.itemValue" :label="dict.itemName" :value="dict.itemValue" />
                  </px-select>
                </template>
              </px-table-column>
              <px-table-column label="排放数量">
                <template #default="scope">
                  <px-input v-model="scope.row.emissionQuantity" style="width: 240px; min-width: 100px" placeholder="排放数量" clearable />
                </template>
              </px-table-column>
              <px-table-column label="操作" align="center" width="120">
                <template #default="scope">
                  <px-button link type="danger" @click="handleDeletewaste(scope.row)"
                    ><px-tooltip class="box-item" effect="light" content="删除" placement="top">
                      <px-icon><Delete /></px-icon> </px-tooltip
                  ></px-button>
                </template>
              </px-table-column>
            </px-table>
          </px-scrollbar>
        </div>
        <div
          class="box-card2"
          :style="{
            height: jiqicanshuFlg == true ? '' : '42px'
          }"
        >
          <div class="card-header" @click="setjiqicanshuFlg()">
            <div class="card-title">危险废弃物</div>
            <div class="card-main">
              <px-icon v-if="!jiqicanshuFlg">
                <ArrowDown />
              </px-icon>
              <px-icon v-else>
                <ArrowUp />
              </px-icon>
            </div>
          </div>
          <px-button style="margin: 16px 0 -11px 23px" type="primary" plain size="small" @click="handleAddtestItems">新增</px-button>
          <px-scrollbar class="form-div">
            <px-table :data="equipdata.wasteMap.HAZARD" border style="width: 100%">
              <px-table-column label="废弃物名称">
                <template #default="scope">
                  <px-select v-model="scope.row.dictWasteCode" placeholder="请选择系统" clearable style="width: 240px" filterable>
                    <px-option v-for="dict in HAZARDlist" :key="dict.dictCode" :label="dict.name" :value="dict.dictCode" />
                  </px-select>
                </template>
              </px-table-column>
              <px-table-column label="排放数量">
                <template #default="scope">
                  <px-input v-model="scope.row.emissionQuantity" style="width: 240px; min-width: 100px" placeholder="排放数量" clearable />
                </template>
              </px-table-column>
              <px-table-column label="操作" align="center" width="120">
                <template #default="scope">
                  <px-button link type="danger" @click="handleDeletedict(scope.row)"
                    ><px-tooltip class="box-item" effect="light" content="删除" placement="top">
                      <px-icon><Delete /></px-icon> </px-tooltip
                  ></px-button>
                </template>
              </px-table-column>
            </px-table>
          </px-scrollbar>
        </div>
      </px-form>
    </px-scrollbar>
    <div v-if="equipopenDetail" class="px-dialog-footer">
      <px-button @click="equipopenDetailcancel">取消</px-button>
      <px-button v-if="fromdisable" type="primary" @click="equipopenDetailcancel">关闭</px-button>
      <px-button v-else type="primary" :disabled="photoStatusFlag || fileStatusFlag" @click="equipopenDetailsubmitForm(detailruleFormRef)"
        >保存</px-button
      >
    </div>
    <px-dialog v-model="progressVisible" draggable clickHideContent title="上传进度" width="30%" center align-center>
      <px-progress :percentage="Math.floor(progressPercent)" />
    </px-dialog>
  </div>
</template>

<script setup name="Dict" lang="ts">
defineOptions({
  name: "SystemDataDict"
});
// import { router } from "@/router";
import { ArrowLeft } from "@px-ui/icons-vue";
import { useRouter, useRoute } from "vue-router";
import { PxMessage, PxMessageBox } from "px-ui";
import { getCurrentInstance, ref, toRefs, reactive, onMounted } from "vue";
import { getToken } from "@/utils/auth";
import { queryChildByTypeCodeAndItemValue } from "@/api/waterClass";
import modelTitle from "@/views/common/components/modelTitle/index.vue";
import {
  chemicalConsumequeryListPage,
  chemicalConsumeadd,
  chemicalConsumeupdate,
  chemicalConsumequeryDetail,
  GENERALChemicalqueryChemicalName,
  commonqueryChemicalNameBySystem
} from "@/api/chemicals";
import {
  emissionqueryListPage,
  emissionaddEmissionPlan,
  emissiondeleteEmissionData,
  emissionupdateEmissionData,
  emissionqueryEmissionDetailData,
  emissiongetGeneralData,
  emissiongetHazardData
} from "@/api/waterPlan";
const props = defineProps({
  classCode: {
    type: String,
    default: "WATER"
  }
});
function handleDeletewaste(row) {
  PxMessageBox.confirm("是否确认删除？", "温馨提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    // type: "warning",
    draggable: true
  })
    .then(async () => {
      equipdata.value.wasteMap.GENERAL = equipdata.value.wasteMap.GENERAL.filter(item => item != row);
      PxMessage({
        message: "删除成功",
        type: "success"
      });
    })
    .catch(() => {});
}
function handleDeletedict(row) {
  PxMessageBox.confirm("是否确认删除？", "温馨提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    // type: "warning",
    draggable: true
  })
    .then(async () => {
      equipdata.value.wasteMap.HAZARD = equipdata.value.wasteMap.HAZARD.filter(item => item != row);
      PxMessage({
        message: "删除成功",
        type: "success"
      });
    })
    .catch(() => {});
}
const jibenxinxiFlg = ref(true);
const defaultTime: [Date, Date] = [new Date(2000, 1, 1, 0, 0, 1), new Date(2000, 1, 1, 23, 59, 59)];
const setqingdanFlg = () => {
  jibenxinxiFlg.value = !jibenxinxiFlg.value;
};
const queysetSystemChemicals = val => {
  commonqueryChemicalNameBySystem({
    chemicalType: "CH01",
    systemCode: val
  }).then(res => {
    console.log(res);
    querychemicalList.value = res;
  });
};
const router = useRouter();
const jiqicanshuFlg = ref(true);
const wasteUnit = ref("吨");
const setjiqicanshuFlg = () => {
  jiqicanshuFlg.value = !jiqicanshuFlg.value;
};
const shebeitaizhangFlg = ref(true);
const setshebeitaizhangFlg = () => {
  shebeitaizhangFlg.value = !shebeitaizhangFlg.value;
};
const moxingshezhiFlg = ref(true);
const setmoxingshezhiFlg = () => {
  moxingshezhiFlg.value = !moxingshezhiFlg.value;
};
const setreceiveCompanyCode = val => {
  let setvalue = null;
  setvalue = liquidList.value.find(option => option.itemValue == val);
  console.log(setvalue);
  if (setvalue && setvalue?.itemDesc != "") {
    equipdata.value.wasteType = JSON.parse(setvalue.itemDesc).type;
    equipdata.value.wasteCode = JSON.parse(setvalue.itemDesc).code;
    equipdata.value.HAZARDCharacteristics = JSON.parse(setvalue.itemDesc).tx;
  } else {
    equipdata.value.wasteType = "";
    equipdata.value.wasteCode = "";
    equipdata.value.HAZARDCharacteristics = "";
  }

  //console.log(setvalue);
};

const setAddreceiveCompanyCode = val => {
  let setvalue = null;
  setvalue = liquidList.value.find(option => option.itemValue == val);
  if (setvalue && setvalue.itemDesc != "") {
    equipdata.value.receiveCompanyCode = JSON.parse(setvalue.itemDesc).receiveCompanyCode;
  } else {
    // equipdata.value.receiveCompanyCode = "";
  }
  //console.log(setvalue);
};
const route = useRoute();
onMounted(() => {
  if (route.params.chukuList) {
    // handleDetail(route.query.equipmentId);
    console.log(chukuList);
  }
});
const { proxy }: any = getCurrentInstance();
const handleAddtestItems = () => {
  equipdata.value.wasteMap.HAZARD.push({
    dictWasteCode: "",
    emissionQuantity: ""
  });
};
const handleAddtestItems2 = () => {
  equipdata.value.wasteMap.GENERAL.push({
    dictWasteCode: "",
    emissionQuantity: ""
  });
};
const typeList = ref([]);
const detailruleFormRef = ref();
const progressVisible = ref(false);
const open = ref(false);
const equipopen = ref(false);
const equipopenDetail = ref(false);
const fromdisable = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const progressPercent = ref(0);
const dateRange = ref([]);

// 图片是否上传完，是否可以保存
const savePhotoStatus = val => {
  photoStatusFlag.value = val;
};
// 文件是否上传完，是否可以保存
const saveFileStatus = val => {
  fileStatusFlag.value = val;
};

const waterstatusList = [
  {
    value: "VALID",
    name: "全部"
  },
  {
    value: "INVALID",
    name: "已删除"
  }
];
const buttonTitle = ref("");
const data = reactive({
  testItems: [
    {
      name: "",
      value: ""
    }
  ],
  testItems2: [
    {
      name: "",
      value: ""
    }
  ],
  liquidList: [],
  transportCompanyList: [],
  receiveCompanyList: [],
  typeIdList: [],
  categoryList: [],
  equipmentTypeList: [],
  positionList: [],
  equipmentDeptList: [],
  modelIdList: [],
  chukuList: [],
  form: {},
  wasteUnitoptions: [
    {
      value: "克",
      label: "克"
    },
    {
      value: "千克",
      label: "千克"
    },
    {
      value: "吨",
      label: "吨"
    }
  ],
  photoStatusFlag: false,
  fileStatusFlag: false,
  equipdata: {
    id: "",
    classCode: props.classCode,
    emissionPlan: "",
    emissionTime: "",
    wasteMap: {
      HAZARD: [
        {
          dictWasteCode: "",
          emissionQuantity: ""
        }
      ],
      GENERAL: [
        {
          dictWasteCode: "",
          emissionQuantity: ""
        }
      ]
    }
  },
  queryParams: {
    orderByColumn: "",
    isAsc: "",
    classCode: props.classCode,
    emissionPlan: "",
    startTime: "",
    endTime: "",
    orderBy: "",
    pageNum: 1,
    pageSize: 20
  },
  rules: {
    emissionTime: [{ required: true, message: "排放时间不能为空", trigger: "change" }],
    emissionPlan: [{ required: true, message: "排放计划不能为空", trigger: "blur" }]
  },
  headers: {
    Authorization: "Bearer " + getToken().accessToken || ""
  },
  moduleName: "",
  dialogImageUrl: "",
  imageVisible: false,
  querychemicalList: [],
  HAZARDlist: [],
  GENERALlist: []
});
const options = [
  {
    itemValue: "system1",
    itemName: "系统1"
  },
  {
    itemValue: "system2",
    itemName: "系统2"
  }
];
const {
  HAZARDlist,
  GENERALlist,
  testItems,
  testItems2,
  querychemicalList,
  liquidList,
  chukuList,
  queryParams,
  form,
  rules,
  equipdata,
  equipmentTypeList,
  modelIdList,
  photoStatusFlag,
  fileStatusFlag,
  wasteUnitoptions
} = toRefs(data);
const checkTime = () => {
  if (equipdata.value.manufactureDate && equipdata.value.warrantyEndDate) {
    if (equipdata.value.manufactureDate > equipdata.value.warrantyEndDate) {
      PxMessage({
        message: "开始时间不能大于结束时间",
        type: "error"
      });
    }
  }
};
function formatDate(date) {
  const year = date.getFullYear();
  const month = (date.getMonth() + 1).toString().padStart(2, "0");
  const day = date.getDate().toString().padStart(2, "0");
  const h = date.getHours().toString().padStart(2, "0");
  const m = date.getMinutes().toString().padStart(2, "0");
  const s = date.getSeconds().toString().padStart(2, "0");
  return `${year}-${month}-${day} ${h}:${m}:${s}`;
}
const getqueryCategoryList = () => {
  const end = new Date();
  end.setHours(23, 59, 59, 0);
  end.setTime(end.getTime());
  const start = new Date();
  start.setHours(0, 0, 0, 0);
  start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  // dateRange.value = [formatDate(start), formatDate(end)];
  queryChildByTypeCodeAndItemValue({
    value: "WATER_SYSTEM",
    typeCode: "WTTS"
  }).then((response: any) => {
    //console.log(response);
    liquidList.value = response;
  });
  emissiongetGeneralData({
    classCode: props.classCode,
    pageNum: 1,
    pageSize: 999
  }).then(res => {
    console.log(res);
    GENERALlist.value = res;
  });
  emissiongetHazardData({
    classCode: props.classCode,
    pageNum: 1,
    pageSize: 999
  }).then(res => {
    console.log(res);
    HAZARDlist.value = res;
  });
};
getqueryCategoryList();
function getList() {
  loading.value = true;
  if (dateRange.value != null) {
    queryParams.value.startTime = dateRange.value[0];
    queryParams.value.endTime = dateRange.value[1];
  } else {
    queryParams.value.startTime = "";
    queryParams.value.endTime = "";
  }

  emissionqueryListPage(queryParams.value).then((response: any) => {
    typeList.value = response.data;
    total.value = response.total;
    loading.value = false;
  });
}

/** 取消按钮 */
function cancel() {
  equipopen.value = false;
}
function equipopenDetailcancel() {
  equipopenDetail.value = false;
}
/** 表单重置 */
function reset() {
  form.value = {
    id: undefined,
    dictionaryName: undefined,
    dictionaryType: undefined,
    status: "VALID",
    remarks: undefined
  };
  proxy.resetForm("dictRef");
}
/** 搜索按钮操作 */
function handleQuery(type) {
  if (type == "search") {
    queryParams.value.pageNum = 1;
  }
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  queryParams.value = {
    pageNum: queryParams.value.pageNum,
    pageSize: queryParams.value.pageSize,
    orderByColumn: "",
    isAsc: "",
    classCode: props.classCode,
    emissionPlan: "",
    startTime: "",
    endTime: "",
    orderBy: ""
  };
  dateRange.value = [];
  handleQuery("reset");
}

/** 新增按钮操作 */
function handleAdd() {
  buttonTitle.value = "新增";
  jibenxinxiFlg.value = true;
  jiqicanshuFlg.value = true;
  shebeitaizhangFlg.value = true;
  moxingshezhiFlg.value = true;
  equipopenDetail.value = true;
  fromdisable.value = false;
  equipmentTypeList.value = [];
  modelIdList.value = [];
  testItems.value = [
    {
      name: "",
      value: ""
    }
  ];
  testItems2.value = [
    {
      name: "",
      value: ""
    }
  ];
  equipdata.value = {
    id: "",
    classCode: props.classCode,
    emissionPlan: "",
    emissionTime: "",
    wasteMap: {
      HAZARD: [
        {
          dictWasteCode: "",
          emissionQuantity: ""
        }
      ],
      GENERAL: [
        {
          dictWasteCode: "",
          emissionQuantity: ""
        }
      ]
    }
  };
}
const handleDetail = async val => {
  jibenxinxiFlg.value = true;
  jiqicanshuFlg.value = true;
  shebeitaizhangFlg.value = true;
  moxingshezhiFlg.value = true;
  const data = await emissionqueryEmissionDetailData({ emissionPlan: val, classCode: props.classCode });
  //console.log(data);

  equipopen.value = true;
  // equipopenDetail.value = true;
  fromdisable.value = true;
  equipdata.value = data;
  //console.log(equipdata);
};

const handleEditor = async val => {
  buttonTitle.value = "编辑";
  jibenxinxiFlg.value = true;
  jiqicanshuFlg.value = true;
  shebeitaizhangFlg.value = true;
  moxingshezhiFlg.value = true;

  const data = await emissionqueryEmissionDetailData({ emissionPlan: val, classCode: props.classCode });
  //console.log(data);
  equipopenDetail.value = true;
  fromdisable.value = false;
  equipdata.value = data;
};
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  chukuList.value = selection;
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 提交按钮 */

const equipopenDetailsubmitForm = async (formEl: any) => {
  if (!formEl) return;
  await formEl.validate(async valid => {
    if (valid) {
      const params = {
        id: equipdata.value.id,
        classCode: equipdata.value.classCode,
        emissionPlan: equipdata.value.emissionPlan,
        emissionTime: equipdata.value.emissionTime,
        wasteMap: equipdata.value.wasteMap,
        createTime: equipdata.value.createTime,
        updateTime: equipdata.value.updateTime
      };
      if (buttonTitle.value == "新增") {
        emissionaddEmissionPlan(params).then((response: any) => {
          PxMessage({
            message: `${buttonTitle.value == "新增" ? "添加成功" : "修改成功"}`,
            type: "success"
          });
          handleQuery("search");
          equipopenDetail.value = false;
        });
      } else {
        emissionupdateEmissionData(params).then((response: any) => {
          PxMessage({
            message: `${buttonTitle.value == "新增" ? "添加成功" : "修改成功"}`,
            type: "success"
          });
          handleQuery("search");
          equipopenDetail.value = false;
        });
      }
    }
  });
};
const handleDelete = val => {
  emissiondeleteEmissionData({
    classCode: props.classCode,
    emissionPlan: val
  })
    .then(res => {
      PxMessage({
        message: `删除成功`,
        type: "success"
      });
      getList();
    })
    .catch(() => {
      PxMessage({
        message: `删除失败`,
        type: "success"
      });
      getList();
    });
};

const { VITE_FANRUAN_BASE_URL, VITE_SERVE_API_STATIC_URL } = import.meta.env;
/** 导出按钮操作 */
function handleExport() {
  if (dateRange.value != null && dateRange.value.length > 0) {
    let Token = getToken().accessToken || "";
    // proxy.download("post", "/operation/api/v1/water/testQuality/pwMetalImpurity/export", queryParams.value, "水质检测-纯水金属阴阳离子.xlsx");
    let url = `${VITE_FANRUAN_BASE_URL}/webroot/decision/view/report?viewlet=water%252F%25E5%258C%2596%25E5%25AD%25A6%25E5%2593%2581%25E7%2594%25A8%25E9%2587%258F%25E8%25AE%25B0%25E5%25BD%2595.cpt&token=${Token}&from=${dateRange.value[0]}&to=${dateRange.value[1]}&location&format=excel&extype=simple&facCode=${localStorage.getItem("facCode") || ""}&apiHost=${VITE_SERVE_API_STATIC_URL}`;
    window.location.href = url;
  } else {
    PxMessage({
      message: "请选择时间后再导出",
      type: "error"
    });
  }
}

getList();
</script>
<style scoped lang="scss">
.addEquip {
  position: absolute;
  top: 0;
  top: 5px;
  left: 0;
  width: calc(100% - 48px);
  height: calc(100% - 40px);
  margin: 24px;
  background: white;
}

.editorEquip {
  position: absolute;
  top: 0;
  top: 5px;
  left: 0;
  width: calc(100% - 48px);
  height: calc(100% - 40px);
  margin: 24px;
  background: white;
}

.px-dialog-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 2002;
  width: 100%;
  height: 50px;
  padding-top: 10px;
  padding-right: 34px;
  text-align: right;
  background: white;
  box-shadow: 0 0 10px 0 rgb(0 0 0 / 16%);
}

.card-header {
  min-height: 40px;
  padding: 14px 15px 7px !important;
  cursor: pointer;
  user-select: none;
  background: #e7eefb;
}

.card-title {
  float: left;
  line-height: 14px;
}

.card-main {
  float: left;
  margin: -3px 8px 0 5px;
  cursor: pointer;
}

.box-card1 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card2 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card3 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card4 {
  width: calc(100% - 48px);
  height: 261px;
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.demo-form-inline {
  .px-input {
    --px-input-width: calc(100% - 100px);
  }

  .px-form-item {
    width: 100%;
  }

  .px-textarea__inner {
    width: calc(100% - 100px) !important;
  }

  .px-form-item__label {
    font-weight: 400 !important;
  }
}

.form-div {
  padding: 24px;

  .px-row {
    margin-bottom: 16px;
  }
}

.px-icon {
  font-size: 16px !important;
}

:deep(.px-tabs__header) {
  // padding-left: 6px !important;
}

:deep(.px-tabs--top .px-tabs__item.is-top.is-active) {
  border: none;

  .pane-bottom {
    line-height: 30px;
    border-bottom: 2px solid #3b82f6;
  }
}

:deep(.px-tabs .px-tabs__item) {
  .pane-bottom {
    line-height: 30px;
  }
}

.pane-line {
  position: absolute;
  top: 12px;
  right: 0;
  height: 15px;
  color: #dcdcdc;
  border-left: 1px solid #dcdcdc;
}

:deep(.custom-form-ui .px-form-item) {
  width: 250px !important;
}

.filename {
  position: absolute;
  bottom: -30px;
  width: 96px;
  overflow: hidden;
  color: rgb(166 167 172);
  text-overflow: ellipsis;
  white-space: nowrap;
}

:deep(.px-descriptions__label.px-descriptions__cell.is-bordered-label) {
  width: 166px;
  background: #e7eefb;
  border: 1px solid #dfdfdf;
}

:deep(.px-descriptions__body .px-descriptions__table.is-bordered .px-descriptions__cell) {
  border: 1px solid #dfdfdf;
}

.cell-item {
  text-align: right;
}

:deep(.px-table__header) {
  thead {
    tr {
      background-color: #e7eefb !important;

      th {
        font-size: 14px;
        font-weight: bold;
        color: #000;
        background-color: #e7eefb !important;
      }
    }
  }
}

:deep(.px-table--isfixedHeader .px-table__header-wrapper .px-table-fixed-column--right) {
  background-color: #e7eefb !important;
}

.tableTop {
  display: flex;
  // border-right: 1px solid #dfdfdf;

  .topList {
    flex: 1;
    min-width: 130px;
    padding: 6px;
    font-size: 14px;
    font-weight: bold;
    line-height: 23px;
    color: #000;
    background-color: #e7eefb !important;
    border: 1px solid #dfdfdf;
    border-right: none;

    &:nth-last-child(1) {
      border-right: 1px solid #dfdfdf;
    }
  }
}

.tableMain {
  display: flex;
  // border-right: 1px solid #dfdfdf;

  .topList {
    flex: 1;
    min-width: 130px;
    padding: 6px;
    font-size: 14px;
    line-height: 23px;
    color: #000;
    border: 1px solid #dfdfdf;
    border-top: none;
    border-right: none;

    &:nth-last-child(1) {
      border-right: 1px solid #dfdfdf;
    }
  }
}
</style>
